package database;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * Opens and close a connection with a Database
 * 
 * @author Nils Berlijn & Henderikus Harms
 */	
public class Connect 
{
	private static final String DRIVER= "com.mysql.jdbc.Driver";
	private static final String URL = "jdbc:mysql://localhost:3306/";
	private static final String DATABASE = "unwdmi";
	private static final String USER = "root";
	private static final String PASSWORD = "";
	
	public static Connection connection;
	
	/**
	 * Open a connection with the Database
	 */
	public static void open()
	{
		try 
		{
		    Class.forName(DRIVER);
		    
		    connection = DriverManager.getConnection(URL + DATABASE, USER, PASSWORD);
		    
		    System.out.println("Connection established with the Database!");
	    }
	    catch(Exception e)
	    {
	    	System.out.println("Couldn't not connect to the Database!");
	    }		
	}
	
	/**
	 * Close a connection with the Database
	 */
	public static void close()
	{
		try 
		{
			connection.close();
			
		    System.out.println("Connection closed with the Database!");			
	    }
	    catch(Exception e)
	    {
	    	System.out.println("Couldn't not close the connection with the Database!");
	    }				
	}
}